/*
 * Copyright (C) 2015-2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#ifndef PLANET_WARS_2D_RT_CORE_MODEL_UNIVERSE_SHIPS_H
#define PLANET_WARS_2D_RT_CORE_MODEL_UNIVERSE_SHIPS_H


#include "PlanetWars2dRT-core/specific/model/universe_essential.h"


EXTERN_C_BEGIN


static inline
size_t
universe_get_nb_ships_unsafe(const universe_t* a_universe)
{
  return VECTOR_GENERIC_STATIC_GET_SIZE(&a_universe->ships);
}

static inline
size_t
universe_get_nb_ships(const universe_t* a_universe)
{
  return a_universe == NULL ? 0 : universe_get_nb_ships_unsafe(a_universe);
}

static inline
const ship_t*
universe_get_const_ships(const universe_t* a_universe)
{
  return VECTOR_GENERIC_STATIC_GET_DATA(&a_universe->ships);
}

static inline
ship_t*
universe_get_ships(universe_t* a_universe)
{
  return VECTOR_GENERIC_STATIC_GET_DATA(&a_universe->ships);
}

static inline
const ship_t*
universe_get_const_ship_no_check(const universe_t* a_universe,
				 size_t index)
{
  return VECTOR_GENERIC_STATIC_GET_ITEM_POINTER_UNSAFE(&a_universe->ships, index);
}

static inline
ship_t*
universe_get_ship_no_check(universe_t* a_universe,
			   size_t index)
{
  return VECTOR_GENERIC_STATIC_GET_ITEM_POINTER_UNSAFE(&a_universe->ships, index);
}

static inline
const ship_t*
universe_get_const_ship(const universe_t* a_universe,
			size_t index)
{
  return
    a_universe != NULL && index < universe_get_nb_ships(a_universe)
    ? universe_get_const_ship_no_check(a_universe, index)
    : NULL;
}

static inline
ship_t*
universe_get_ship(universe_t* a_universe,
		  size_t index)
{
  return
    a_universe != NULL && index < universe_get_nb_ships(a_universe)
    ? universe_get_ship_no_check(a_universe, index)
    : NULL;
}

static inline
void
universe_set_ship_no_check(universe_t* a_universe,
			   size_t index,
			   const ship_t* a_ship)
{
  VECTOR_GENERIC_STATIC_SET_ITEM_VALUE_UNSAFE(&a_universe->ships, index,
					      *a_ship);
}


static inline
void
universe_add_ship_no_check_no_notify(universe_t*   a_universe,
				     const ship_t* ship_to_add)
{
  VECTOR_GENERIC_STATIC_PUSH_BACK(&a_universe->ships, *ship_to_add, ship_t);
}

void
universe_add_ship_no_check(universe_t*   a_universe,
			   const ship_t* ship_to_add);

bool
universe_add_ship_unsafe_no_notify(universe_t*   a_universe,
				   const ship_t* ship_to_add);

bool
universe_add_ship_unsafe(universe_t*   a_universe,
			 const ship_t* ship_to_add);

bool
universe_add_ship_no_notify(universe_t*   a_universe,
			    const ship_t* ship_to_add);

bool
universe_add_ship(universe_t*   a_universe,
		  const ship_t* ship_to_add);


void
universe_remove_ships_no_notify(universe_t* a_universe);

void
universe_remove_ships(universe_t* a_universe);

/**
 * @return Number of destroyed ships
 */
size_t
universe_remove_destroyed_ships_no_notify(universe_t* a_universe);

/**
 * @return Number of destroyed ships
 */
size_t
universe_remove_destroyed_ships(universe_t* a_universe);


EXTERN_C_END


#endif
